package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CHomePage
import com.onlyphoto.onlymall.mvp.model.MHomePageImpl
import com.onlyphoto.onlymall.base.BasePresenter
import com.onlyphoto.onlymall.bean.response.GoodsBean
import com.onlyphoto.onlymall.bean.response.Rotation
import com.onlyphoto.onlymall.bean.response.SingleActivityBean


class PHomePageImpl(mContext: Context, mView: CHomePage.IVHomePage) : BasePresenter<CHomePage.IVHomePage, MHomePageImpl>(mContext, mView, MHomePageImpl()), CHomePage.IPHomePage {

    override fun requestRotation() {
        mModel.requestRotation(object : BaseObserver<ArrayList<Rotation>>(mContext.get()){
            override fun onSuccess(data: ArrayList<Rotation>?, msg: String?) {
                mView.requestRotationSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<ArrayList<Rotation>>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }
        })
    }

    override fun requestActivitySingle(use_range: Int, range_cat1_id: Int) {
        mModel.requestSingleActivity(use_range, range_cat1_id, object : BaseObserver<SingleActivityBean>(mContext.get()){
            override fun onSuccess(data: SingleActivityBean?, msg: String?) {
                mView.requestActivitySingleSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<SingleActivityBean>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }

    override fun requestGoods() {
        val condition = mView.setCondition()
        mModel.requestGoods(condition, object :BaseObserver<ArrayList<GoodsBean>>(mContext.get()){
            override fun onSuccess(data: ArrayList<GoodsBean>?, msg: String?) {
                mView.requestGoodsSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<ArrayList<GoodsBean>>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
                mView.showLoading()
            }

            override fun onFinally() {
                mView.hideLoading()
            }

        })
    }

}
